package main

import (
	"github.com/asim/go-micro/plugins/registry/consul/v3"
	"github.com/asim/go-micro/v3/registry"
	"github.com/asim/go-micro/v3/web"
	"github.com/gin-gonic/gin"
	"log"
	_ "server/docs"
	"server/middle_ware"
	AllRouter "server/router"
)

// @title BlockChain
// @version latest
// @description BlockChainDevelop
// @termsOfService http://swagger.io/terms/

// @contact.name lsr
// @contact.url http://www.swagger.io/support
// @contact.email support@swagger.io

// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html

// @host 127.0.0.1:8081
// @BasePath /
func main() {
	// gin 引擎
	router := gin.Default()

	//进行路由绑定
	AllRouter.RouterAll(router)

	//防止跨域
	router.Use(middle_ware.Cors)

	//consul 注册
	register := consul.NewRegistry(func(options *registry.Options) {
		options.Addrs = []string{"43.138.147.44:8500"}
	})

	//服务注册
	service := web.NewService(
		web.Name("develop_web"),
		web.Version("latest"),
		web.RegisterTTL(10),
		web.Registry(register),
		web.RegisterInterval(1),
		web.Handler(router),
		web.Address(":8081"),
	)

	//初始化
	service.Init()

	//运行服务
	if err := service.Run(); err != nil {
		log.Fatal(err)
	}
}
